package com.fneuch.mwg.w40k.rule;

import com.fneuch.mwg.rules.Probability;
import com.fneuch.mwg.rules.dice.Dice;
import com.fneuch.mwg.rules.dice.DiceProbability;

public class AbstractRuleEngine {

	protected static int[][] woundChart = {
			{4, 5, 6, 6,-1,-1,-1,-1,-1,-1}, // Strength 1
			{3, 4, 5, 6, 6,-1,-1,-1,-1,-1}, // Strength 2
			{2, 3, 4, 5, 6, 6,-1,-1,-1,-1}, // Strength 3
			{2, 2, 3, 4, 5, 6, 6,-1,-1,-1}, // Strength 4
			{2, 2, 2, 3, 4, 5, 6, 6,-1,-1}, // Strength 5
			{2, 2, 2, 2, 3, 4, 5, 6, 6,-1}, // Strength 6
			{2, 2, 2, 2, 2, 3, 4, 5, 6, 6}, // Strength 7
			{2, 2, 2, 2, 2, 2, 3, 4, 5, 6}, // Strength 8
			{2, 2, 2, 2, 2, 2, 2, 3, 4, 5}, // Strength 9
			{2, 2, 2, 2, 2, 2, 2, 2, 3, 4}, // Strength 10
		};
	
	protected Probability probability = new DiceProbability(Dice.D6);

	public AbstractRuleEngine() {
		super();
	}

	public int toWound(int strengthValue, int toughnessValue) {
		int retour = 0;
		int strengthNeeded = strengthValue-1 < 0 ? 0 : strengthValue-1;
		int toughnessNeeded = toughnessValue-1 < 0 ? 0 : toughnessValue-1;
		int statsNeeded = woundChart[strengthNeeded][toughnessNeeded];
		if(statsNeeded > 0) {
			retour = probability.over(statsNeeded); 
		}
		
		return retour;
	}

	public int toSave(int saveValue) {
		return probability.over(saveValue);
	}

}